package com.eben
 

class Main implements Serializable {
    static final String STATE_FAILED = "failed"
    static final String STATE_ABORTED = "aborted"
    static final String STATE_RUNNING = "running"
    static final String STATE_SUCCESS = "succeeded"

   
    def script
    def env
    def startTime
    def result

    Main(Object script, String env) {
        this.script = script
        this.env = env
        this.startTime = new Date().time
        this.result = [
            uuid: script.params.uuid,
            build_number: script.env.BUILD_NUMBER,
            artifacts: [:],
            state: STATE_RUNNING,
            browse_url: "${script.env.BUILD_URL}console",
            stages: [:],
            duration: 0,
            error_message: ""
        ]
    }

    def run() {
        start()

        script.node {
            script.echo(script.params.param1)
            script.cleanWs()
            script.echo('hello')
        }
            
    }

    def start() {
    }

    def fail() {
        result.state = STATE_FAILED
    }

    def success() {
        result.state = STATE_SUCCESS
    }

    def setDuration() {
        this.result.duration = new Date().time - startTime
    }
}
